<?php
/*$textarea文本
 * $thisurl 本网址
 * $clhc
 * $thisbaseurl网站根地址
 * */
function geshitext($textarea, $thisurl="", $clhc=0, $thisbaseurl = "",$lie_a=false)
{
    if (is_string($textarea)) {
        $textarea = utf8encode($textarea);
        $textarea = strip_jscss($textarea, $lie_a); //#### todo 过滤函数
        $textarea = preg_replace("/width\>/Uisx", "width&gt;", $textarea);
        $textarea = preg_replace("/(<img[^<>]*)\s+?\/>/Uisx", "\\1>", $textarea);
        $textarea = preg_replace("/<span[^<>]*style=\\\?\"display\:none\\\?\"[^<>]*>.*<\/span>/Uisx", "", trim($textarea));
        $textarea = preg_replace("/<span[^<>]*>|<\/\s*span>/Uisx", "", $textarea);
        $textarea = preg_replace("/\(微博\)/m", "", trim($textarea));
        $textarea = preg_replace("/([0-9]+\-[0-9]+\-[0-9]+\s[0-9]+\:[0-9]+\:[0-9]+\s上传).*$/m", "", $textarea);
        $textarea = preg_replace("/<(\/?)(b|strong)\s*\/?>/Uisx", "[\\1b]", $textarea);
        $textarea = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $textarea);
        $textarea = preg_replace("/<\!\-\-enpproperty(?=\<)|(?<=\>)\/enpproperty\-\->|<\!\-\-\/?enpproperty\-\->/i", "", trim($textarea));
        $textarea = preg_replace("/([0-9\-]+\s+[0-9\:]+|[0-9]天前)\s*(上传|修改|发表|更新)/Uisx", "", trim($textarea));
        $textarea = preg_replace("/<fieldset[^<>]*>(.*)<\/fieldset>/Uisx", "", trim($textarea));
        $textarea = str_replace('src="static/image/common/none.gif" ', '', $textarea);
        $textarea = str_replace('zoomfile', 'src', $textarea);
        $textarea = preg_replace("/<\/?br\s*\/?>|&lt;\/br\s*\/?&gt;/Uisx", "\r\n", $textarea);
        $textarea = htmltotxt($textarea, $clhc, $thisurl, $thisbaseurl, $lie_a);
        $textarea = preg_replace("/\[img\][^<>\[\]]*(\/images?\/smiley|images?\/common\/|\/images?\/smilies\/|\/miba\/images\/|images\/attachicons\/|\/common\/cf\/)[^<>\[\]]*\[\/img\]|\[b\]下载\[\/b\]|\([0-9\.a-z\s]+KB\)|[0-9]+天前[0-9\:]+?|附件\:\s*您所在的用户组无法下载或查看附件|<\/?blockquote[^<>]*>/Uisx", "", $textarea);
        $textarea = preg_replace("/\([\s0-9\.]+KB\,?\s*(下载次数\:\s*[\s0-9]+)?\)|下载次数\:[\s0-9]+?|(\s|　)[^\s]+\.jpg(\s|　)/Uisx", "\r\n", $textarea);
        $textarea = preg_replace("/本帖.*[0-9\-\s\:]编辑|<\/img>|<br\s*\/>|\&lt\;br\s*\/\&gt\;/Uisx", "", $textarea);
        $textarea = preg_replace("/本主题由[^\r\n]*/isx", "", $textarea);
        $textarea = preg_replace("/保存到相册|点击文件名|马上注册，.*？注册|\[img\][^<>\[\]]*qq_login.gif\[\/img\]/Uisx", "", $textarea);
        $textarea = preg_replace("/　　回复.*$/Uisx", "", $textarea);
        //$textarea = preg_replace("/(\r(\s)*\n)+|[\r\n](\s|[\x{3000}])*[\r\n]+/u", "\n", $textarea);
        $textarea = preg_replace("/[\r\n]+　　(\[hr\]\s*)+/", "[hr]", $textarea);
        $textarea = preg_replace("/(?:\[hr\]([\x{3000}]|\s)*)+/u", "[hr]", $textarea);
    } else if (is_array($textarea)) {
        foreach ($textarea as $k => $v) {
            $textarea[$k] = deletePublic($v, $thisurl, $clhc);
        }
    }
    return $textarea;
}

function strip_jscss($str, $lie_a = false)
{
    preg_match_all("/<script\b[^<>]*>.*<\/\s*script\s*\/?>/Uisx", $str, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/reload|AC_FL_RunContent/Uisx", $nn[0][$i])) {
            if (preg_match("/http\:\/\/([^<>]*.swf)/Uisx", $nn[0][$i], $mm)) {
                $str = str_replace($nn[0][$i], "[media=swf,500,375]{$mm[0]}[/media]", $str);
                continue;
            }
        }
        $str = str_replace($nn[0][$i], "", $str);
    }
    $str = preg_replace("/<SCRIPT\b[^<>]*>.*(<\/\s*script\s*\/?>|$)/Uisx", "", $str);
    $str = preg_replace("/<select\b[^<>]*>.*(<\/\s*select\s*\/?>|$)/Uisx", "", $str);
    $str = preg_replace("/<\/?br\s*\/?>|&lt;\/br\s*\/?&gt;/Uisx", "\r\n", $str);
    $str = preg_replace("/<style\b[^<>]*>.*<\/\s*style\s*\/?>/Uisx", "", $str);
    $str = preg_replace("/<img[^<>]*src=\"[^<>]*\"[^<>]*file=\"([^<>]*)\"[^<>]*>/Uisx", "<img src=\"\\1\">", $str);
    $str = preg_replace("/(?<![=\"\'\]\[\,])(http\:\/\/[^<>]*\.(jpg|gif|png))/Uisx", "<img src=\"\\1\">", $str);
    $str = preg_replace("/([0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2}|(半|[0-9])(小时|天)前)[^<>]*下载附件[^<>]*KB\)/", "", $str);
    return $str;
}


function htmltotxt($str, $n = 0, $thisurl = "", $thisbaseurl = "", $lie_a = false)
{
    global $rs;
    $str = trim($str);
    $str = strip_tags2($str, "strong|b|a|p|img|br|td|table|tr|ul|li|span|hr", $lie_a);
    //$str=preg_replace("/\"/", "\\\"",$str);
    preg_match_all("/<img(.*)(?<!width|height|\=|\.|width\s)>/Uisx", $str, $nn00);
    for ($i = 0; $i < count($nn00[1]); $i++) {
        $tmp = preg_replace("/\\\(?!\'|\")/", "/", $nn00[0][$i]);
        preg_match_all("/file\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn3);
        $src = trim($nnn3[1][0]);
        if ($src == "") {
            preg_match_all("/original\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn2);
            $src = trim($nnn2[1][0]);
        }
        if ($src == "") {
            preg_match_all("/(?:real_src|data-lazyload-src|data-original|crs|src[0-9]+)\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn2);
            $src = trim($nnn2[1][0]);
        }
        if ($src == "") {
            preg_match_all("/src[0-9\s]*\=[\s\\\?\"\']*?([^<>\\\'\"]*)((?<=jpeg|png|gif|jpg)\s|'|\"|>|$)/Uisx", $tmp, $nnn2);
            $src = trim($nnn2[1][0]);
        }
        if ($rs['loadimg'] == 1) {
            $str = str_replace($nn00[0][$i], "\r\n[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" . surlencode(quanurl(trim($src), $thisurl, $thisbaseurl)) . "[/img]\r\n<p>\r\n", $str);
        } else {
            $str = str_replace($nn00[0][$i], "\r\n&nbsp;\r\n[img]" . quanurl(trim($src), $thisurl, $thisbaseurl) . "[/img]\r\n<p>\r\n&nbsp;\r\n", $str);
        }
    }
    $str = preg_replace("/\&ldquo\;/Uisx", "\"", $str);
    $str = preg_replace("/\&rdquo\;/Uisx", "\"", $str);
    $str = preg_replace("/<(\/?)\s*(br|p)[^<>]*>/isx", "\r\n", $str);
    $str = preg_replace("/(\r\s*\n)+/m", "\r\n", $str);
    $str = preg_replace("/<(\/?)(td|table|tr|li|ul)\b([^<>]*)>/Uisx", "", $str);
    $str = preg_replace("/\[img\][^<>\[\]]*Array\[\/img\]/Usx", "", $str);
    $str = preg_replace("/^\s*　　\s*(http\:\/\/[^<>]*\.jpg)\s*$/Uixm", "\r\n　　[img]\\1[/img]\r\n", $str);
    if(!function_exists('callbackfun01')){
        function callbackfun01($em) {
            global $thisurl, $thisbaseurl;
            if(trim(strip_tags(preg_replace("/\&nbsp\;/Uisx","",$em[2])))!="") {
                if(preg_match("/\[img\].*\[\/img\]/Uisx",$em[2])){
                    return trim(strip_tags($em[2]));
                }else{
                    return "[url=" . quanurl(trim(strip_tags($em[1])), $thisurl, $thisbaseurl) . "]" . trim(strip_tags($em[2])) . "[/url]";
                }
            }else{
                return "";
            }
        }
    }
    $str = preg_replace_callback("/<a[^<>]*href=['\"]([^<>]+)['\"][^<>]*>(.*)<\/a>/Uisx", "callbackfun01", $str);
    $str = preg_replace("/(\]|。|；|？)(　|\s)+/Uisx", "\\1\r\n　　", $str);
    $str = preg_replace("/" . g("(\]|。|；|？)(　|\s)+") . "/Uisx", "\\1\r\n　　", $str);
    $str = trim(preg_replace("/^(　|\s|\&nbsp\;)*$/Uisxu", "\r\n　　", $str));
    $str = str_replace('\"', '"', $str);
    return trim($str);
}


function deletePublic($textarea, $thisurl, $clhc, $thisbaseurl = "", $lie_a = false)
{
    if (is_string($textarea)) {
        $textarea = utf8encode($textarea);
        $textarea = strip_jscss($textarea, $lie_a); //#### todo 过滤函数
        $textarea = preg_replace("/width\>/Uisx", "width&gt;", $textarea);
        $textarea = preg_replace("/(<img[^<>]*)\s+?\/>/Uisx", "\\1>", $textarea);
        $textarea = preg_replace("/<span[^<>]*style=\\\?\"display\:none\\\?\"[^<>]*>.*<\/span>/Uisx", "", trim($textarea));
        $textarea = preg_replace("/<span[^<>]*>|<\/\s*span>/Uisx", "", $textarea);
        $textarea = preg_replace("/\(微博\)/m", "", trim($textarea));
        $textarea = preg_replace("/([0-9]+\-[0-9]+\-[0-9]+\s[0-9]+\:[0-9]+\:[0-9]+\s上传).*$/m", "", $textarea);
        $textarea = preg_replace("/<(\/?)(b|strong)\s*\/?>/Uisx", "[\\1b]", $textarea);
        $textarea = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $textarea);
        $textarea = preg_replace("/<\!\-\-enpproperty(?=\<)|(?<=\>)\/enpproperty\-\->|<\!\-\-\/?enpproperty\-\->/i", "", trim($textarea));
        $textarea = preg_replace("/([0-9\-]+\s+[0-9\:]+|[0-9]天前)\s*(上传|修改|发表|更新)/Uisx", "", trim($textarea));
        $textarea = preg_replace("/<fieldset[^<>]*>(.*)<\/fieldset>/Uisx", "", trim($textarea));
        $textarea = str_replace('src="static/image/common/none.gif" ', '', $textarea);
        $textarea = str_replace('zoomfile', 'src', $textarea);
        $textarea = preg_replace("/<\/?br\s*\/?>|&lt;\/br\s*\/?&gt;/Uisx", "\r\n", $textarea);
        $textarea = htmltotxt($textarea, $clhc, $thisurl, $thisbaseurl, $lie_a);
        $textarea = preg_replace("/\[img\][^<>\[\]]*(\/images?\/smiley|images?\/common\/|\/images?\/smilies\/|\/miba\/images\/|images\/attachicons\/|\/common\/cf\/)[^<>\[\]]*\[\/img\]|\[b\]下载\[\/b\]|\([0-9\.a-z\s]+KB\)|[0-9]+天前[0-9\:]+?|附件\:\s*您所在的用户组无法下载或查看附件|<\/?blockquote[^<>]*>/Uisx", "", $textarea);
        $textarea = preg_replace("/\([\s0-9\.]+KB\,?\s*(下载次数\:\s*[\s0-9]+)?\)|下载次数\:[\s0-9]+?|(\s|　)[^\s]+\.jpg(\s|　)/Uisx", "\r\n", $textarea);
        $textarea = preg_replace("/本帖.*[0-9\-\s\:]编辑|<\/img>|<br\s*\/>|\&lt\;br\s*\/\&gt\;/Uisx", "", $textarea);
        $textarea = preg_replace("/本主题由[^\r\n]*/isx", "", $textarea);
        $textarea = preg_replace("/保存到相册|点击文件名|马上注册，.*？注册|\[img\][^<>\[\]]*qq_login.gif\[\/img\]/Uisx", "", $textarea);
        $textarea = preg_replace("/　　回复.*$/Uisx", "", $textarea);
        //$textarea = preg_replace("/(\r(\s)*\n)+|[\r\n](\s|[\x{3000}])*[\r\n]+/u", "\n", $textarea);
        $textarea = preg_replace("/[\r\n]+　　(\[hr\]\s*)+/", "[hr]", $textarea);
        $textarea = preg_replace("/(?:\[hr\]([\x{3000}]|\s)*)+/u", "[hr]", $textarea);
    } else if (is_array($textarea)) {
        foreach ($textarea as $k => $v) {
            $textarea[$k] = deletePublic($v, $thisurl, $clhc);
        }
    }
    return $textarea;
}


function quanurl($subUrl, $wurl, $baseurl = "")
{
    if(is_string($subUrl)) $subUrl=urldecode($subUrl);
    if (is_array($subUrl) || $subUrl == "") return "";
    preg_match("/(https?)\:\/\//Uisx",$wurl,$nn);
    $https=$nn[1];
    $baseurl = preg_replace("/(https?\:\/\/[^\/]+)$/Uisx", "\\1/", $baseurl);
    if(!preg_match("/(https?\:\/\/[^\/]+)$/Uisx",$baseurl)){
        $baseurl="";
    }
    $subUrl = str_replace('\\', "/", trim($subUrl));
    $subUrl = str_replace('&amp;', "&", $subUrl);
    $subUrl = preg_replace("/^\.\?/", "?", $subUrl);
    $wurl = ($baseurl) ? $baseurl : $wurl;
    $wurl = preg_replace("/\?.*$/Uisx", "", $wurl);
    preg_match_all("/(https?\:\/\/([^\/]*?))(.*)$/Uimx", $wurl, $mm);
    $host = $mm[2][0];
    $subUrl=preg_replace("/^\/\//",$https."://",$subUrl);
    if (substr($subUrl, 0, 7) == "http://"||substr($subUrl, 0, 8) == "https://") {
        $newurl = $subUrl;
    } elseif (preg_match("/^\//", $subUrl)) {
        $newurl = "{$https}://" . $host . $subUrl;
    } elseif (preg_match("/^\.\.\//", $subUrl)) {
        $tmsuburl = $subUrl;
        $tempparentUrl = $wurl;
        preg_match_all("/(\.\.\/)/Uisx", $subUrl, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            $tmsuburl = preg_replace("/^\.\.\//", "", $tmsuburl);
            if(!preg_match("/https?\:\/\/[^<>\/]+\/?$/Uisx",$tempparentUrl)) {
                $tempparentUrl = preg_replace("/(?!<\/)\/[^<>\/]*\/[^<>\/]*$/", "/", $tempparentUrl);
            }
        }
        $newurl = preg_replace("/\/$/", "", $tempparentUrl) . "/" . $tmsuburl;
    } elseif (preg_match("/^[^\.\/\?]/", $subUrl)) {
        preg_match("/^(.*)\//Uisx", $subUrl, $nna);
        preg_match("/https?\:\/\/.*\/(.*)\//Uisx", $wurl, $nnb);
        if ($nnb[1] == $nna[1]) {
            $newurl = $https."://" . $host . "/" . $subUrl;
        } else {
            $newurl = dirname2($wurl) . "/" . $subUrl;
        }
    } elseif (preg_match("/^\?/", $subUrl)) {
        $newurl = preg_replace("/\?.*$/U", "", $wurl) . $subUrl;
    } else {
        $newurl = preg_replace("/\/[^\/]*$/", "/", $wurl) . $subUrl;
    }
    $newurl = preg_replace("/\/\.\//", "/", $newurl);
    $newurl = preg_replace("/\/https?\:\//", "/", $newurl);
    $newurl = preg_replace("/[\r\n]/", "", $newurl);
    return $newurl;
}


function dquanurl($nr, $wurl, $baseurl)
{
    $nr = preg_replace("/(src|location|<link[^>]*href|<EMBED[^>]*VALUE|action|background|imgurl|<PARAM\s+NAME\=movie\s+VALUE|href)\s*=\s*(\"|\')?([^\"\'\>\s]+)(\\2|(?=\>)|\s)/Uisxe", "'\\1=\"'.quanurl('\\3','$wurl',\"$baseurl\").'\"'", $nr);
    $nr = preg_replace("/url\((\"|'|)?([^<>\s\"']+)\\1\)/Uisxe", '"url(".quanurl("\\2",$wurl).")"', $nr);
    //$nr=stripCSlashes($nr);
    return $nr;
}

function dirname2($wurl)
{
    if (substr($wurl, -1, 1) == "/") {
        return substr($wurl, 0, -1);
    } else {
        return dirname($wurl);
    }
}

function host($str)
{
    $str=urldecode($str);
    preg_match_all("/https?\:\/\/(?:[^<>\/]*?)([a-z0-9_]+?\.(?:com|gov|edu|org|mobi|la|us|hk|tw|net|cn|vn|cc|info)(?:(?:\.net|\.cn|\.cc|\.tv|\.hk|\.tw|\.info|\.vn)*(?=\:|\/|$)))/isx", $str, $nn);
    $host = $nn[1][0];
    $host = preg_replace("/^(?:[^<>]*\.)*([a-z0-9_]+\.(com|gov|edu|org|cn|mobi|la|hk|tw|us|cc|info|vn))/Uisx", "\\1", $host);
    if($host==""&&preg_match("/https?\:\/\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/",$str,$nn)){
        $host=$nn[1];
    }
    return $host;
}



function strip_tags2($str, $s, $lie_a = false)
{
    if(!function_exists('cbfun91')){
        function cbfun91($nn){
            return $nn[1]."=\"".strip_tags3($nn[2])."\"";
        }
    }
    $str = preg_replace_callback("/(desc|alt)=\"(.*)\"/Uisx","cbfun91", $str);

    if ($lie_a) {
        $str = preg_replace("/<(?!\/|" . $s . "|script|b|strong|a\b).*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
        $str = preg_replace("/<\/(?!" . $s . "|script|b|strong|a\b).*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
    } else {
        $str = preg_replace("/<(?!\/|" . $s . "|script|b|strong).*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
        $str = preg_replace("/<\/(?!" . $s . "|script|b|strong).*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
    }
    return $str;

}

function strip_tags3($str)
{
    $str = preg_replace("/\&lt\;.*\&gt\;/Uisx", "", $str);
    return $str;

}


function addsla2($str, $args = array())
{
    $nn = preg_split("/@@/", $str);
    $n = 0;

    do {
        preg_match_all("/.*?(\(\.\*\)|\(\.\+\)|\(\[\^\<\>\]\*\)|\\\\\\/|\(\[[<>\+\\\-_a-z\%\/0-9\^\$]+\]\*\)|\:y\b|\:nn[0-9]+?|\.\*|\[[<>\+\\\-_a-z\%\/0-9\^\$]+\]|\[0\-9\]|\{标题\}|\{内容\}|\{变量[0-9]+\}|\\\"|\\\(|\\\)|\\\'|\\\s+|\\\r|\\\n|\+|\*|\\\$|\\\^)/isx", trim($nn[0]), $mm);
        $replace_times = 1;
        $nn[0] = str_replace($mm[1][0], "&&" . $n . "&&", $nn[0], $replace_times);
        $GLOBALS[arr][$n] = $mm[1][0];
        $n++;
    } while (count($mm[1]) > 0 && $n < 5);
    $nn[0] = addsla($nn[0]);
    if(!function_exists('cbfun2')) {
        function cbfun2($it)
        {
            return $GLOBALS[arr][$it[1]];
        }
    }
    $nn[0] = preg_replace_callback("/&&([0-9]+)&&/Uisx", "cbfun2", $nn[0]);
    $nn[0] = str_replace("\\", "\\\\", $nn[0]);
    if (count($nn) == 1) {
        return $nn[0];
    } else {
        return $nn[0] . "@@" . $nn[1];
    }
    unset($GLOBALS['arr']);
}


function utf8encode($source)
{
    if (is_string($source)) {
        if (!preg_match("/\\\u[a-z0-9]{4}|%u[a-z0-9]{4}|\&\#[a-z0-9]{4,5}/", $source)) {
            return $source;
        }
    }

    $utf8str = '';
    $source = preg_replace('/\\\u/', '%u', $source);
    $source = convert_entities($source);
    $entities = explode('&#', $source);
    $size = count($entities);

    for ($i = 0; $i < $size; $i++) {
        $foo = $entities[$i];
        $nonEntity = strstr($foo, ';');

        if ($nonEntity !== false) {
            $unicode = intval(substr($foo, 0, (strpos($foo, ';') + 1)));
            // determine how many chars are needed to reprsent this unicode char
            if ($unicode < 128) {
                $bar = chr($unicode);
            } else if ($unicode >= 128 and $unicode < 2048) {
                $binVal = str_pad(decbin($unicode), 11, '0', STR_PAD_LEFT);
                $binPart1 = substr($binVal, 0, 5);
                $binPart2 = substr($binVal, 5);

                $char1 = chr(192 + bindec($binPart1));
                $char2 = chr(128 + bindec($binPart2));
                $bar = $char1 . $char2;
            } else if ($unicode >= 2048 and $unicode < 65536) {
                $binVal = str_pad(decbin($unicode), 16, '0', STR_PAD_LEFT);
                $binPart1 = substr($binVal, 0, 4);
                $binPart2 = substr($binVal, 4, 6);
                $binPart3 = substr($binVal, 10);

                $char1 = chr(224 + bindec($binPart1));
                $char2 = chr(128 + bindec($binPart2));
                $char3 = chr(128 + bindec($binPart3));
                $bar = $char1 . $char2 . $char3;
            } else {
                $binVal = str_pad(decbin($unicode), 21, '0', STR_PAD_LEFT);
                $binPart1 = substr($binVal, 0, 3);
                $binPart2 = substr($binVal, 3, 6);
                $binPart3 = substr($binVal, 9, 6);
                $binPart4 = substr($binVal, 15);

                $char1 = chr(240 + bindec($binPart1));
                $char2 = chr(128 + bindec($binPart2));
                $char3 = chr(128 + bindec($binPart3));
                $char4 = chr(128 + bindec($binPart4));
                $bar = $char1 . $char2 . $char3 . $char4;
            }

            if (strlen($nonEntity) > 1) {
                $nonEntity = substr($nonEntity, 1); // chop the first char (';')
            } else {
                $nonEntity = '';
            }
            $utf8str .= $bar . $nonEntity;
        } else {
            $utf8str .= $foo;
        }
    }
    $utf8str = preg_replace("/(\\\\)+n/", "", $utf8str);
    if (preg_match("/http\:\\\\\/\\\\\//", $utf8str)) {
        //$utf8str = stripcslashes($utf8str);
    }
    return $source;
    //return $utf8str;
}

function convert_entities($str)
{
    $str = preg_replace_callback('|%u([a-f0-9]{4})|i',
        create_function(
            '$matches',
            'return \'&#\' . hexdec($matches[1]) . \';\';'
        ),
        $str
    );
    return $str;
}


if (!function_exists("g")) {
    function g($text)
    {
        if (is_array($text)) {
            $new = array();
            foreach ($text as $k => $v) {
                $new[g($k)] = g($v);
            }
            $text = $new;
        }
        if (is_object($text)) {
            $text = array2object(g(object2array($text)));
        }
        if (is_string($text)) {
            $text = iconv("UTF-8", "GB2312//IGNORE", $text);
        }
        return $text;
    }
}

function object2array(&$object)
{
    $object = json_decode(json_encode($object), true);
    return $object;
}

function array2object($arrGiven)
{
    $objResult = new stdClass();
    foreach ($arrGiven as $key => $value) {
        if (is_array($value)) $value = array2object($value);
        $objResult->{$key} = $value;
    }
    return $objResult;
}

echo geshitext("fdsagfdsgfsgr");